let app = getApp();
//替换成开发者后台设置的安全域名
let url = "http://smallroutine.changyuelife.com/eapp";
import 'dingtalk-jsapi/entry/mobile';
import openLink from 'dingtalk-jsapi/api/biz/util/openLink';
Page({
    data: {
        // tab切换 
        currentTab: 0,
        listinfo: '',
        display: 'none',
    },
    swichNav(e) {
        var that = this;
        if (that.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current,
            })
        }
    },
    onLoad() {
        let _this = this;

        dd.getAuthCode({
            success: (res) => {
                let AuthCode = res.authCode;
                dd.httpRequest({
                    url: url + '/login',
                    method: 'POST',
                    data: {
                        authCode: AuthCode
                    },
                    dataType: 'json',
                    success: function (res) {
                        let userInfo = res.data.result;
                        dd.setStorage({
                            key: 'userinfo',
                            data: {
                                nick: userInfo.nick,
                                openid: userInfo.openid,
                                unionid: userInfo.unionid,
                            },
                            success: function () {
                                dd.httpRequest({
                                    url: url + '/findApprovalList',
                                    method: 'POST',
                                    data: {
                                        authCode: res.authCode,
                                        unionid: userInfo.unionid
                                    },
                                    dataType: 'json',
                                    success: function (res) {
                                        let listinfo = res.data.recordList;
                                        if (listinfo && listinfo != '') {
                                            _this.setData({
                                                listinfo: listinfo
                                            })
                                            // console.log(listinfo)   
                                        } else {
                                            _this.setData({
                                                display: 'block'
                                            })
                                        }
                                    },
                                });

                            }

                        });
                    },
                });

            }
        })

    },
    onReady: function () {
        // 生命周期函数--监听页面初次渲染完成
    },
    onShow: function () {
        // 生命周期函数--监听页面显示
    },
    onHide: function () {
        // 生命周期函数--监听页面隐藏
    },
    onUnload: function () {
        // 生命周期函数--监听页面卸载
    },
    onPullDownRefresh: function () {
        // 页面相关事件处理函数--监听用户下拉动作
    },
    onReachBottom: function () {
        // 页面上拉触底事件的处理函数
    },
    onShareAppMessage: function () {
        // 用户点击右上角分享
        return {
            title: 'title', // 分享标题
            desc: 'desc', // 分享描述
            path: 'path' // 分享路径
        }
    }
})